package 第一个程序;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPServer {
    public static void main(String[] args) throws IOException {
        ServerSocket ss = null;
        Socket s = null;
        try {
            ss =  new ServerSocket(9999);
            s = ss.accept();
            InputStream in = s.getInputStream();
            byte [] buf = new byte[1024];
            int num = in.read(buf);
            String str = new String(buf , 0 , num);
            System.out.println(s.getInetAddress().toString() + ":" + str);
            s.close();
            ss.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
